package com.atguigu.springcloud.service.impl;

import com.atguigu.springcloud.service.IMessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

/**
 * @author : wenchao.long
 * @date : Created in 2020/12/21 8:07 周一
 * @description :
 *         <p>
 *         定义消息的推送管道 @EnableBinding(Source.class)
 *         相当于output
 *         </p>
 */
@EnableBinding(Source.class)
@Slf4j
public class MessageProviderImpl implements IMessageProvider {

    /**
     * 消息发送管道
     */
    @Autowired
    private MessageChannel output;

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        Message<String> build = MessageBuilder.withPayload(serial).build();
        output.send(build);
        log.info("============serial" + serial);
        return "" + build;
    }

}
